var TurndownService = function () {
    "use strict";

    function i(e, n) {
        return Array(n + 1).join(e)
    }

    function o(e) {
        return -1 !== w.indexOf(e.nodeName.toLowerCase())
    }

    function r(e) {
        return -1 !== N.indexOf(e.nodeName.toLowerCase())
    }

    function t(e) {
        for (var n in this.options = e, this._keep = [], this._remove = [], this.blankRule = {replacement: e.blankReplacement}, this.keepReplacement = e.keepReplacement, this.defaultRule = {replacement: e.defaultReplacement}, this.array = [], e.rules) this.array.push(e.rules[n])
    }

    function a(e, n, t) {
        var r, i;
        for (r = 0; r < e.length; r++) if (l(i = e[r], n, t)) return i
    }

    function l(e, n, t) {
        var r = e.filter;
        if ("string" == typeof r) {
            if (r === n.nodeName.toLowerCase()) return !0
        } else if (Array.isArray(r)) {
            if (-1 < r.indexOf(n.nodeName.toLowerCase())) return !0
        } else {
            if ("function" != typeof r) throw new TypeError("`filter` needs to be a string, array, or function");
            if (r.call(e, n, t)) return !0
        }
    }

    function f(e) {
        var n = e.nextSibling || e.parentNode;
        return e.parentNode.removeChild(e), n
    }

    function d(e, n, t) {
        return e && e.parentNode === n || t(n) ? n.nextSibling || n.parentNode : n.firstChild || n.nextSibling || n.parentNode
    }

    function c(e) {
        var n;
        return function (e) {
            var n, t, r, i, o, a, l = e.element, c = e.isBlock, u = e.isVoid, s = e.isPre || function (e) {
                return "PRE" === e.nodeName
            };
            if (l.firstChild && !s(l)) {
                for (t = !1, i = d(r = n = null, l, s); i !== l;) {
                    if (3 === i.nodeType || 4 === i.nodeType) {
                        if (o = i.data.replace(/[ \r\n\t]+/g, " "), n && !/ $/.test(n.data) || t || " " !== o[0] || (o = o.substr(1)), !o) {
                            i = f(i);
                            continue
                        }
                        i.data = o, n = i
                    } else {
                        if (1 !== i.nodeType) {
                            i = f(i);
                            continue
                        }
                        c(i) || "BR" === i.nodeName ? (n && (n.data = n.data.replace(/ $/, "")), n = null, t = !1) : u(i) && (t = !(n = null))
                    }
                    a = d(r, i, s), r = i, i = a
                }
                n && (n.data = n.data.replace(/ $/, ""), n.data || f(n))
            }
        }({
            element: n = "string" == typeof e ? (v = v || new y).parseFromString('<x-turndown id="turndown-root">' + e + "</x-turndown>", "text/html").getElementById("turndown-root") : e.cloneNode(!0),
            isBlock: o,
            isVoid: r
        }), n
    }

    function u(e) {
        var n, t;
        return e.isBlock = o(e), e.isCode = "code" === e.nodeName.toLowerCase() || e.parentNode.isCode, e.isBlank = -1 === ["A", "TH", "TD"].indexOf((n = e).nodeName) && /^\s*$/i.test(n.textContent) && !r(n) && !((t = n).querySelector && t.querySelector(C)), e.flankingWhitespace = function (e) {
            var n, t, r = "", i = "";
            e.isBlock || (n = /^[ \r\n\t]/.test(e.textContent), t = /[ \r\n\t]$/.test(e.textContent), n && !s("left", e) && (r = " "), t && !s("right", e) && (i = " "));
            return {leading: r, trailing: i}
        }(e), e
    }

    function s(e, n) {
        var t, r, i;
        return "left" === e ? (t = n.previousSibling, r = / $/) : (t = n.nextSibling, r = /^ /), t && (3 === t.nodeType ? i = r.test(t.nodeValue) : 1 !== t.nodeType || o(t) || (i = r.test(t.textContent))), i
    }

    function p(e) {
        if (!(this instanceof p)) return new p(e);
        var n = {
            rules: S,
            headingStyle: "setext",
            hr: "* * *",
            bulletListMarker: "*",
            codeBlockStyle: "indented",
            fence: "```",
            emDelimiter: "_",
            strongDelimiter: "**",
            linkStyle: "inlined",
            linkReferenceStyle: "full",
            br: "  ",
            blankReplacement: function (e, n) {
                return n.isBlock ? "\n\n" : ""
            },
            keepReplacement: function (e, n) {
                return n.isBlock ? "\n\n" + n.outerHTML + "\n\n" : n.outerHTML
            },
            defaultReplacement: function (e, n) {
                return n.isBlock ? "\n\n" + e + "\n\n" : e
            }
        };
        this.options = function (e) {
            var n, t, r;
            for (n = 1; n < arguments.length; n++) for (r in t = arguments[n]) t.hasOwnProperty(r) && (e[r] = t[r]);
            return e
        }({}, n, e), this.rules = new t(this.options)
    }

    function h(e) {
        var r = this;
        return n.call(e.childNodes, function (e, n) {
            var t = "";
            return 3 === (n = new u(n)).nodeType ? t = n.isCode ? n.nodeValue : r.escape(n.nodeValue) : 1 === n.nodeType && (t = function (e) {
                var n = this.rules.forNode(e), t = h.call(this, e), r = e.flankingWhitespace;
                (r.leading || r.trailing) && (t = t.trim());
                return r.leading + n.replacement(t, e, this.options) + r.trailing
            }.call(r, n)), m(e, t)
        }, "")
    }

    function m(e, n) {
        var t, r, i, o = (t = n, r = [e.match(b)[0], t.match(k)[0]].sort(), (i = r[r.length - 1]).length < 2 ? i : "\n\n");
        return (e = e.replace(b, "")) + o + (n = n.replace(k, ""))
    }

    var g, y, v, n, k, b, e,
        w = ["address", "article", "aside", "audio", "blockquote", "body", "canvas", "center", "dd", "dir", "div", "dl", "dt", "fieldset", "figcaption", "figure", "footer", "form", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "html", "isindex", "li", "main", "menu", "nav", "noframes", "noscript", "ol", "output", "p", "pre", "section", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "ul"],
        N = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"],
        C = N.join(), S = {};
    return S.paragraph = {
        filter: "p", replacement: function (e) {
            return "\n\n" + e + "\n\n"
        }
    }, S.lineBreak = {
        filter: "br", replacement: function (e, n, t) {
            return t.br + "\n"
        }
    }, S.heading = {
        filter: ["h1", "h2", "h3", "h4", "h5", "h6"], replacement: function (e, n, t) {
            var r = Number(n.nodeName.charAt(1));
            return "setext" === t.headingStyle && r < 3 ? "\n\n" + e + "\n" + i(1 === r ? "=" : "-", e.length) + "\n\n" : "\n\n" + i("#", r) + " " + e + "\n\n"
        }
    }, S.blockquote = {
        filter: "blockquote", replacement: function (e) {
            return "\n\n" + (e = (e = e.replace(/^\n+|\n+$/g, "")).replace(/^/gm, "> ")) + "\n\n"
        }
    }, S.list = {
        filter: ["ul", "ol"], replacement: function (e, n) {
            var t = n.parentNode;
            return "LI" === t.nodeName && t.lastElementChild === n ? "\n" + e : "\n\n" + e + "\n\n"
        }
    }, S.listItem = {
        filter: "li", replacement: function (e, n, t) {
            var r, i, o, a;
            return e = e.replace(/^\n+/, "").replace(/\n+$/, "\n").replace(/\n/gm, "\n    "), r = t.bulletListMarker + "   ", "OL" === (i = n.parentNode).nodeName && (o = i.getAttribute("start"), a = Array.prototype.indexOf.call(i.children, n), r = (o ? Number(o) + a : a + 1) + ".  "), r + e + (n.nextSibling && !/\n$/.test(e) ? "\n" : "")
        }
    }, S.indentedCodeBlock = {
        filter: function (e, n) {
            return "indented" === n.codeBlockStyle && "PRE" === e.nodeName && e.firstChild && "CODE" === e.firstChild.nodeName
        }, replacement: function (e, n, t) {
            return "\n\n    " + n.firstChild.textContent.replace(/\n/g, "\n    ") + "\n\n"
        }
    }, S.fencedCodeBlock = {
        filter: function (e, n) {
            return "fenced" === n.codeBlockStyle && "PRE" === e.nodeName && e.firstChild && "CODE" === e.firstChild.nodeName
        }, replacement: function (e, n, t) {
            var r = n.firstChild.className || "", i = (r.match(/language-(\S+)/) || [null, ""])[1];
            return "\n\n" + t.fence + i + "\n" + n.firstChild.textContent + "\n" + t.fence + "\n\n"
        }
    }, S.horizontalRule = {
        filter: "hr", replacement: function (e, n, t) {
            return "\n\n" + t.hr + "\n\n"
        }
    }, S.inlineLink = {
        filter: function (e, n) {
            return "inlined" === n.linkStyle && "A" === e.nodeName && e.getAttribute("href")
        }, replacement: function (e, n) {
            var t = n.getAttribute("href"), r = n.title ? ' "' + n.title + '"' : "";
            return "[" + e + "](" + t + r + ")"
        }
    }, S.referenceLink = {
        filter: function (e, n) {
            return "referenced" === n.linkStyle && "A" === e.nodeName && e.getAttribute("href")
        }, replacement: function (e, n, t) {
            var r, i, o, a = n.getAttribute("href"), l = n.title ? ' "' + n.title + '"' : "";
            switch (t.linkReferenceStyle) {
                case"collapsed":
                    r = "[" + e + "][]", i = "[" + e + "]: " + a + l;
                    break;
                case"shortcut":
                    r = "[" + e + "]", i = "[" + e + "]: " + a + l;
                    break;
                default:
                    r = "[" + e + "][" + (o = this.references.length + 1) + "]", i = "[" + o + "]: " + a + l
            }
            return this.references.push(i), r
        }, references: [], append: function (e) {
            var n = "";
            return this.references.length && (n = "\n\n" + this.references.join("\n") + "\n\n", this.references = []), n
        }
    }, S.emphasis = {
        filter: ["em", "i"], replacement: function (e, n, t) {
            return e.trim() ? t.emDelimiter + e + t.emDelimiter : ""
        }
    }, S.strong = {
        filter: ["strong", "b"], replacement: function (e, n, t) {
            return e.trim() ? t.strongDelimiter + e + t.strongDelimiter : ""
        }
    }, S.code = {
        filter: function (e) {
            var n = e.previousSibling || e.nextSibling, t = "PRE" === e.parentNode.nodeName && !n;
            return "CODE" === e.nodeName && !t
        }, replacement: function (e) {
            var n, t, r, i;
            if (!e.trim()) return "";
            if (n = "`", r = t = "", i = e.match(/`+/gm)) for (/^`/.test(e) && (t = " "), /`$/.test(e) && (r = " "); -1 !== i.indexOf(n);) n += "`";
            return n + t + e + r + n
        }
    }, S.image = {
        filter: "img", replacement: function (e, n) {
            var t = n.alt || "", r = n.getAttribute("src") || "", i = n.title || "", o = i ? ' "' + i + '"' : "";
            return r ? "![" + t + "](" + r + o + ")" : ""
        }
    }, t.prototype = {
        add: function (e, n) {
            this.array.unshift(n)
        }, keep: function (e) {
            this._keep.unshift({filter: e, replacement: this.keepReplacement})
        }, remove: function (e) {
            this._remove.unshift({
                filter: e, replacement: function () {
                    return ""
                }
            })
        }, forNode: function (e) {
            return e.isBlank ? this.blankRule : (n = a(this.array, e, this.options)) ? n : (n = a(this._keep, e, this.options)) ? n : (n = a(this._remove, e, this.options)) ? n : this.defaultRule;
            var n
        }, forEach: function (e) {
            for (var n = 0; n < this.array.length; n++) e(this.array[n], n)
        }
    }, g = "undefined" != typeof window ? window : {}, y = function () {
        var e = g.DOMParser, n = !1;
        try {
            (new e).parseFromString("", "text/html") && (n = !0)
        } catch (e) {
        }
        return n
    }() ? g.DOMParser : ((e = function () {
    }).prototype.parseFromString = function () {
        var n = !1;
        try {
            document.implementation.createHTMLDocument("").open()
        } catch (e) {
            window.ActiveXObject && (n = !0)
        }
        return n
    }() ? function (e) {
        var n = new window.ActiveXObject("htmlfile");
        return n.designMode = "on", n.open(), n.write(e), n.close(), n
    } : function (e) {
        var n = document.implementation.createHTMLDocument("");
        return n.open(), n.write(e), n.close(), n
    }, e), n = Array.prototype.reduce, k = /^\n*/, b = /\n*$/, p.prototype = {
        turndown: function (e) {
            if (null == (n = e) || "string" != typeof n && (!n.nodeType || 1 !== n.nodeType && 9 !== n.nodeType && 11 !== n.nodeType)) throw new TypeError(e + " is not a string, or an element/document/fragment node.");
            var n;
            if ("" === e) return "";
            var t = h.call(this, new c(e));
            return function (n) {
                var t = this;
                return this.rules.forEach(function (e) {
                    "function" == typeof e.append && (n = m(n, e.append(t.options)))
                }), n.replace(/^[\t\r\n]+/, "").replace(/[\t\r\n\s]+$/, "")
            }.call(this, t)
        }, use: function (e) {
            if (Array.isArray(e)) for (var n = 0; n < e.length; n++) this.use(e[n]); else {
                if ("function" != typeof e) throw new TypeError("plugin must be a Function or an Array of Functions");
                e(this)
            }
            return this
        }, addRule: function (e, n) {
            return this.rules.add(e, n), this
        }, keep: function (e) {
            return this.rules.keep(e), this
        }, remove: function (e) {
            return this.rules.remove(e), this
        }, escape: function (e) {
            return e.replace(/\\(\S)/g, "\\\\$1").replace(/^(#{1,6} )/gm, "\\$1").replace(/^([-*_] *){3,}$/gm, function (e, n) {
                return e.split(n).join("\\" + n)
            }).replace(/^(\W* {0,3})(\d+)\. /gm, "$1$2\\. ").replace(/^([^\\\w]*)[*+-] /gm, function (e) {
                return e.replace(/([*+-])/g, "\\$1")
            }).replace(/^(\W* {0,3})> /gm, "$1\\> ").replace(/\*+(?![*\s\W]).+?\*+/g, function (e) {
                return e.replace(/\*/g, "\\*")
            }).replace(/_+(?![_\s\W]).+?_+/g, function (e) {
                return e.replace(/_/g, "\\_")
            }).replace(/`+(?![`\s\W]).+?`+/g, function (e) {
                return e.replace(/`/g, "\\`")
            }).replace(/[\[\]]/g, "\\$&")
        }
    }, p
}();
var turndownPluginGfm = function (e) {
    "use strict";

    function t(e) {
        e.addRule("highlightedCodeBlock", {
            filter: function (e) {
                var t = e.firstChild;
                return "DIV" === e.nodeName && o.test(e.className) && t && "PRE" === t.nodeName
            }, replacement: function (e, t, n) {
                var r = t.className || "", i = (r.match(o) || [null, ""])[1];
                return "\n\n" + n.fence + i + "\n" + t.firstChild.textContent + "\n" + n.fence + "\n\n"
            }
        })
    }

    function n(e) {
        e.addRule("strikethrough", {
            filter: ["del", "s", "strike"], replacement: function (e) {
                return "~" + e + "~"
            }
        })
    }

    function f(e, t) {
        var n = l.call(t.parentNode.childNodes, t), r = " ";
        return 0 === n && (r = "| "), r + e + " |"
    }

    function r(e) {
        for (var t in a) e.addRule(t, a[t])
    }

    function i(e) {
        e.addRule("taskListItems", {
            filter: function (e) {
                return "checkbox" === e.type && "LI" === e.parentNode.nodeName
            }, replacement: function (e, t) {
                return (t.checked ? "[x]" : "[ ]") + " "
            }
        })
    }

    var o = /highlight-(?:text|source)-([a-z0-9]+)/, l = Array.prototype.indexOf, s = Array.prototype.every, a = {};
    return a.tableCell = {
        filter: ["th", "td"], replacement: function (e, t) {
            return f(e, t)
        }
    }, a.tableRow = {
        filter: "tr", replacement: function (e, t) {
            var n, r, i, o, l, a, c, d = "", u = {left: ":--", right: "--:", center: ":-:"};
            if ("THEAD" === (c = (o = t).parentNode).nodeName || c.firstChild === o && ("TABLE" === c.nodeName || (a = (l = c).previousSibling, "TBODY" === l.nodeName && (!a || "THEAD" === a.nodeName && /^\s*$/i.test(a.textContent)))) && s.call(o.childNodes, function (e) {
                return "TH" === e.nodeName
            })) for (n = 0; n < t.childNodes.length; n++) r = "---", (i = (t.childNodes[n].getAttribute("align") || "").toLowerCase()) && (r = u[i] || r), d += f(r, t.childNodes[n]);
            return "\n" + e + (d ? "\n" + d : "")
        }
    }, a.table = {
        filter: "table", replacement: function (e) {
            return "\n\n" + (e = e.replace("\n\n", "\n")) + "\n\n"
        }
    }, a.tableSection = {
        filter: ["thead", "tbody", "tfoot"], replacement: function (e) {
            return e
        }
    }, e.gfm = function (e) {
        e.use([t, n, r, i])
    }, e.highlightedCodeBlock = t, e.strikethrough = n, e.tables = r, e.taskListItems = i, e
}({});